/**
 * 关于设备登录相关的类型
 */

import { IScene } from "../base";
import { IMessage } from "./Message";
import { ISession } from "./Session";

export interface IImConnectData {
  online?: boolean;
  loginports: ILoginPort[];
}

/**
* 多端同时登录, LoginPort代表一个登录端
*/
export interface ILoginPort {
  /** 登录的设备类型 */
  type: IDeviceType;	
  /** 登录设备的操作系统 */
  os: ILoginPortOs;
  /** 登录设备的 mac 地址 */
  mac?: string;
  /** 登录设备ID, uuid */
  deviceId?: string;
  /** 登录的帐号 */
  account?: string;
  /** 登录设备的连接号 */
  connectionId: string;
  /** 登录的服务器 */
  ip?: string;
  /** 登录时间 */
  time?: number;
  /**
   * 是否在线
   * @todo 此字段暂时无用 默认记录存在即是代表在线
   */
  online?: boolean;
}


/**
 * 'Android' (安卓)
 * 'iOS' (苹果)
 * 'PC' (桌面)
 * 'WindowsPhone' (微软)
 * 'Web' (浏览器)
 */
export type IDeviceType = 'h5' | 'web' | 'mini' | 'app';

/** 系统类型 */
export type ILoginPortOs = 'android' | 'ios' | 'linux' | 'windows' | 'mac';

export interface IBlackItem {
  account: string;
  create_at: number;
}

export interface IMuteItem {
  account: string;
  create_at: number;
}

/**
 * 云端客户端通信协议
 */
export type IImDeviceEvent = IImDeviceEventMessage | IImDeviceEventLogin | IImDeviceEventSyncMessage | IImDeviceEventSetCurrSession | IImDeviceEventUpdateSession | IImDeviceEventUpdateSessionField | IImDeviceEventInvokeDeleteSession | IImDeviceEventOnDeleteSession | IImDeviceEventMsgRcvAck;

interface IImDeviceEventBase {
  emid?: string;
}

export interface IImDeviceEventLogin extends IImDeviceEventBase {
  type: 'login';
}

/**
 * 接收新消息
 */
export interface IImDeviceEventMessage extends IImDeviceEventBase {
  type: 'msg';
  msg: IMessage;
  session: ISession;
}

/**
 * 来自其他端的的自己发送的消息
 */
export interface IImDeviceEventSyncMessage extends IImDeviceEventBase {
  type: 'syncmsg';
  msg: IMessage;
  session: ISession;
}

/**
 * 更新会话
 */
export interface IImDeviceEventUpdateSession extends IImDeviceEventBase {
  type: 'session';
  session: ISession;
}

/**
 * 【To Server】进入会话消息
 */
export interface IImDeviceEventSetCurrSession extends IImDeviceEventBase {
  type: 'setCurrSession';
  account: string;
  sessionId: string;
}

/**
 * 【To Server】更新会话信息
 */
export interface IImDeviceEventUpdateSessionField extends IImDeviceEventBase {
  type: 'updateSession';
  account: string;
  sessionId: string;
  /* 可更新字段 */
  isTop?: boolean;
  topCustom?: object;
  custom?: object;
  /** true 则未读数+1 */
  unread?: boolean;
  /** 如果传入则重写未读数 */
  unreadNum?: number;
}

/**
 * 【To Server】删除会话
 */
export interface IImDeviceEventInvokeDeleteSession extends IImDeviceEventBase {
  type: 'invokeDeleteSession';
  account: string;
  scene: string;
  to: string;
}

/**
 * 【To Client】接收到删除会话通知
 */
export interface IImDeviceEventOnDeleteSession extends IImDeviceEventBase {
  type: 'onDeleteSession';
  scene: string;
  to: string;
}

/**
 * 【To Server】接收到消息的回执
 */
export interface IImDeviceEventMsgRcvAck extends IImDeviceEventBase {
  type: 'msgRcvAck';
  account: string;
  client: string;
  msg: IMessage;
}
